package com.woniu.rear.comm.web.feign;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.woniu.rear.comm.core.code.ConstData;
import com.woniu.rear.comm.web.util.ServletUtil;

import feign.RequestInterceptor;
import feign.RequestTemplate;

/**
   *   配置Feign的拦截器,用于传递Token
 * @author liwei
 *
 */
@Component
public class TokenInterceptor implements RequestInterceptor{

	@Override
	public void apply(RequestTemplate template) {
		HttpServletRequest request = ServletUtil.getRequest();
		String token = request.getHeader(ConstData.TOKEN);
		if(!StringUtils.isEmpty(token)) {
			template.header(ConstData.TOKEN, token);
		}
	}

}
